
package xbean.__;

import java.io.StringReader;
import java.io.StringWriter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.goldhuman.Common.Marshal.OctetsStream;
import com.goldhuman.Common.Marshal.MarshalException;

public final class ServerId extends xdb.XBean implements xbean.ServerId {
	private java.util.ArrayList<Integer> sid; // null

	@Override
	public void _reset_unsafe_() {
		sid.clear();
	}

	ServerId(int __, xdb.XBean _xp_, String _vn_) {
		super(_xp_, _vn_);
		sid = new java.util.ArrayList<Integer>();
	}

	public ServerId() {
		this(0, null, null);
	}

	public ServerId(ServerId _o_) {
		this(_o_, null, null);
	}

	ServerId(xbean.ServerId _o1_, xdb.XBean _xp_, String _vn_) {
		super(_xp_, _vn_);
		if (_o1_ instanceof ServerId) {
			assign((ServerId)_o1_);
		} else if (_o1_ instanceof ServerId.Data) {
			assign((ServerId.Data)_o1_);
		} else if (_o1_ instanceof ServerId.Const) {
			assign(((ServerId.Const)_o1_).nThis());
		} else {
			throw new UnsupportedOperationException();
		}
	}

	private void assign(ServerId _o_) {
		_o_._xdb_verify_unsafe_();
		sid = new java.util.ArrayList<Integer>();
		sid.addAll(_o_.sid);
	}

	private void assign(ServerId.Data _o_) {
		sid = new java.util.ArrayList<Integer>();
		sid.addAll(_o_.sid);
	}

	@Override
	public final OctetsStream marshal(OctetsStream _os_) {
		_xdb_verify_unsafe_();
		try {
			StringWriter sw = new StringWriter();
			JsonWriter _out_ = new JsonWriter(sw);
			marshal(_out_);
			_os_.marshalJson(sw.getBuffer().toString());
			_out_.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void marshal(JsonWriter _out_) throws Exception {
		_out_.beginObject();
		if (sid.size() != 0) {
			_out_.name("1");
			_out_.beginArray();
			for (Integer _v_ : this.sid) {
				_out_.value(_v_);
			}
			_out_.endArray();
		}
		_out_.endObject();
	}

	@Override
	public final OctetsStream unmarshal(OctetsStream _os_) {
		_xdb_verify_unsafe_();
		try {
			JsonReader jr = new JsonReader(new StringReader(_os_.unmarshalJson()));
			unmarshal(jr);
			jr.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void unmarshal(JsonReader _in_) throws Exception {
		_in_.beginObject();
		while (_in_.hasNext()) {
			switch (_in_.nextName()) {
				case "1":
					_in_.beginArray();
					while (_in_.hasNext()) {
						int _v_ = 0;
						_v_ = _in_.nextInt();
						this.sid.add(_v_);
					}
					_in_.endArray();
					break;
				default:
					_in_.skipValue();
					break;
			}
		}
		_in_.endObject();
	}

	@Override
	public xbean.ServerId copy() {
		_xdb_verify_unsafe_();
		return new ServerId(this);
	}

	@Override
	public xbean.ServerId toData() {
		_xdb_verify_unsafe_();
		xbean.__.ServerId.Data tmp = (Data) xbean.Pod.newServerIdData();
		tmp.assign(this);
		return tmp;
	}

	public xbean.ServerId toBean() {
		_xdb_verify_unsafe_();
		return new ServerId(this); // same as copy()
	}

	@Override
	public xbean.ServerId toDataIf() {
		_xdb_verify_unsafe_();
		return new Data(this);
	}

	public xbean.ServerId toBeanIf() {
		_xdb_verify_unsafe_();
		return this;
	}

	@Override
	public xdb.Bean toConst() {
		_xdb_verify_unsafe_();
		return new Const();
	}

	@Override
	public java.util.List<Integer> getSid() { // null
		_xdb_verify_unsafe_();
		return xdb.Logs.logList(new xdb.LogKey(this, "sid"), sid);
	}

	public java.util.List<Integer> getSidAsData() { // null
		_xdb_verify_unsafe_();
		java.util.List<Integer> sid;
		ServerId _o_ = this;
		sid = new java.util.ArrayList<Integer>();
		sid.addAll(_o_.sid);
		return sid;
	}

	@Override
	public final boolean equals(Object _o1_) {
		_xdb_verify_unsafe_();
		ServerId _o_ = null;
		if ( _o1_ instanceof ServerId ) {
			_o_ = (ServerId)_o1_;
		} else if ( _o1_ instanceof ServerId.Const ) {
			_o_ = ((ServerId.Const)_o1_).nThis();
		} else {
			return false;
		}
		if (!sid.equals(_o_.sid)) {
			return false;
		}
		return true;
	}

	@Override
	public final int hashCode() {
		_xdb_verify_unsafe_();
		int _h_ = 0;
		_h_ += sid.hashCode();
		return _h_;
	}

	@Override
	public String toString() {
		_xdb_verify_unsafe_();
		StringBuilder _sb_ = new StringBuilder();
		_sb_.append("(");
		_sb_.append(sid);
		_sb_.append(")");
		return _sb_.toString();
	}

	@Override
	public xdb.logs.Listenable newListenable() {
		xdb.logs.ListenableBean lb = new xdb.logs.ListenableBean();
		lb.add(new xdb.logs.ListenableChanged().setVarName("sid"));
		return lb;
	}

	private class Const implements xbean.ServerId {
		ServerId nThis() {
			return ServerId.this;
		}

		@Override
		public void _reset_unsafe_() {
			throw new UnsupportedOperationException();
		}

		@Override
		public xbean.ServerId copy() {
			return ServerId.this.copy();
		}

		@Override
		public xbean.ServerId toData() {
			return ServerId.this.toData();
		}

		public xbean.ServerId toBean() {
			return ServerId.this.toBean();
		}

		@Override
		public xbean.ServerId toDataIf() {
			return ServerId.this.toDataIf();
		}

		public xbean.ServerId toBeanIf() {
			return ServerId.this.toBeanIf();
		}

		@Override
		public java.util.List<Integer> getSid() { // null
			_xdb_verify_unsafe_();
			return xdb.Consts.constList(sid);
		}

		public java.util.List<Integer> getSidAsData() { // null
			_xdb_verify_unsafe_();
			ServerId _o_ = ServerId.this;
			java.util.List<Integer> sid;
			sid = new java.util.ArrayList<Integer>();
			sid.addAll(_o_.sid);
			return sid;
		}

		@Override
		public xdb.Bean toConst() {
			_xdb_verify_unsafe_();
			return this;
		}

		@Override
		public boolean isConst() {
			_xdb_verify_unsafe_();
			return true;
		}

		@Override
		public boolean isData() {
			return ServerId.this.isData();
		}

		@Override
		public OctetsStream marshal(OctetsStream _os_) {
			return ServerId.this.marshal(_os_);
		}

		@Override
		public OctetsStream unmarshal(OctetsStream arg0) throws MarshalException {
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public void marshal(JsonWriter _out_) throws Exception {
			ServerId.this.marshal(_out_);
		}

		@Override
		public void unmarshal(JsonReader _in_) throws Exception {
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public xdb.Bean xdbParent() {
			return ServerId.this.xdbParent();
		}

		@Override
		public boolean xdbManaged() {
			return ServerId.this.xdbManaged();
		}

		@Override
		public String xdbVarname() {
			return ServerId.this.xdbVarname();
		}

		@Override
		public Long xdbObjId() {
			return ServerId.this.xdbObjId();
		}

		@Override
		public boolean equals(Object obj) {
			return ServerId.this.equals(obj);
		}

		@Override
		public int hashCode() {
			return ServerId.this.hashCode();
		}

		@Override
		public String toString() {
			return ServerId.this.toString();
		}

	}

	public static final class Data implements xbean.ServerId {
		private java.util.ArrayList<Integer> sid; // null

		@Override
		public void _reset_unsafe_() {
			sid.clear();
		}

		public Data() {
			sid = new java.util.ArrayList<Integer>();
		}

		Data(xbean.ServerId _o1_) {
			if (_o1_ instanceof ServerId) {
				assign((ServerId)_o1_);
			} else if (_o1_ instanceof ServerId.Data) {
				assign((ServerId.Data)_o1_);
			} else if (_o1_ instanceof ServerId.Const) {
				assign(((ServerId.Const)_o1_).nThis());
			} else {
				throw new UnsupportedOperationException();
			}
		}

		private void assign(ServerId _o_) {
			sid = new java.util.ArrayList<Integer>();
			sid.addAll(_o_.sid);
		}

		private void assign(ServerId.Data _o_) {
			sid = new java.util.ArrayList<Integer>();
			sid.addAll(_o_.sid);
		}

	@Override
	public final OctetsStream marshal(OctetsStream _os_) {
		try {
			StringWriter sw = new StringWriter();
			JsonWriter _out_ = new JsonWriter(sw);
			marshal(_out_);
			_os_.marshalJson(sw.getBuffer().toString());
			_out_.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void marshal(JsonWriter _out_) throws Exception {
		_out_.beginObject();
		if (sid.size() != 0) {
			_out_.name("1");
			_out_.beginArray();
			for (Integer _v_ : this.sid) {
				_out_.value(_v_);
			}
			_out_.endArray();
		}
		_out_.endObject();
	}

	@Override
	public final OctetsStream unmarshal(OctetsStream _os_) {
		try {
			JsonReader jr = new JsonReader(new StringReader(_os_.unmarshalJson()));
			unmarshal(jr);
			jr.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void unmarshal(JsonReader _in_) throws Exception {
		_in_.beginObject();
		while (_in_.hasNext()) {
			switch (_in_.nextName()) {
				case "1":
					_in_.beginArray();
					while (_in_.hasNext()) {
						int _v_ = 0;
						_v_ = _in_.nextInt();
						this.sid.add(_v_);
					}
					_in_.endArray();
					break;
				default:
					_in_.skipValue();
					break;
			}
		}
		_in_.endObject();
	}

		@Override
		public xbean.ServerId copy() {
			return new Data(this);
		}

		@Override
		public xbean.ServerId toData() {
			xbean.__.ServerId.Data tmp = (Data) xbean.Pod.newServerIdData();
			tmp.assign(this);
			return tmp;
		}

		public xbean.ServerId toBean() {
			return new ServerId(this, null, null);
		}

		@Override
		public xbean.ServerId toDataIf() {
			return this;
		}

		public xbean.ServerId toBeanIf() {
			return new ServerId(this, null, null);
		}

		// xdb.Bean interface. Data Unsupported
		public boolean xdbManaged() {
			throw new UnsupportedOperationException();
		}
		public xdb.Bean xdbParent() {
			throw new UnsupportedOperationException();
		}
		public String xdbVarname()  {
			throw new UnsupportedOperationException();
		}
		public Long xdbObjId() {
			throw new UnsupportedOperationException();
		}
		public xdb.Bean toConst() {	
			throw new UnsupportedOperationException();
		}
		public boolean isConst() {
			return false;
		}
		public boolean isData() {
			return true;
		}

		@Override
		public java.util.List<Integer> getSid() { // null
			return sid;
		}

		@Override
		public java.util.List<Integer> getSidAsData() { // null
			return sid;
		}

		@Override
		public final boolean equals(Object _o1_) {
			if (!(_o1_ instanceof ServerId.Data)) {
				return false;
			}
			ServerId.Data _o_ = (ServerId.Data) _o1_;
			if (!sid.equals(_o_.sid)) {
				return false;
			}
			return true;
		}

		@Override
		public final int hashCode() {
			int _h_ = 0;
			_h_ += sid.hashCode();
			return _h_;
		}

		@Override
		public String toString() {
			StringBuilder _sb_ = new StringBuilder();
			_sb_.append("(");
			_sb_.append(sid);
			_sb_.append(")");
			return _sb_.toString();
		}

	}
}
